/*     */ package com.cr.framework.manager.factory;
/*     */ 
/*     */ import com.cr.common.utils.AddressUtils;
/*     */ import com.cr.common.utils.LogUtils;
/*     */ import com.cr.common.utils.ServletUtils;
/*     */ import com.cr.common.utils.ShiroUtils;
/*     */ import com.cr.common.utils.MyStringUtils;
/*     */ import com.cr.common.utils.spring.SpringUtils;
/*     */ import com.cr.framework.shiro.session.OnlineSession;
/*     */ import com.cr.system.domain.SysLogininfor;
/*     */ import com.cr.system.domain.SysOperLog;
/*     */ import com.cr.system.domain.SysUserOnline;
/*     */ import com.cr.system.service.ISysOperLogService;
/*     */ import com.cr.system.service.ISysUserOnlineService;
/*     */ import com.cr.system.service.impl.SysLogininforServiceImpl;
/*     */ import eu.bitwalker.useragentutils.UserAgent;
/*     */ import java.util.TimerTask;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ 
/*     */ public class AsyncFactory {
/*  30 */   private static final Logger sys_user_logger = LoggerFactory.getLogger("sys-user");
/*     */   
/*     */   public static TimerTask syncSessionToDb(final OnlineSession session) {
/*  40 */     return new TimerTask() {
/*     */         public void run() {
/*  45 */           SysUserOnline online = new SysUserOnline();
/*  46 */           online.setSessionId(String.valueOf(session.getId()));
/*  47 */           online.setDeptName(session.getDeptName());
/*  48 */           online.setLoginName(session.getLoginName());
/*  49 */           online.setStartTimestamp(session.getStartTimestamp());
/*  50 */           online.setLastAccessTime(session.getLastAccessTime());
/*  51 */           online.setExpireTime(Long.valueOf(session.getTimeout()));
/*  52 */           online.setIpaddr(session.getHost());
/*  53 */           online.setLoginLocation(AddressUtils.getRealAddressByIP(session.getHost()));
/*  54 */           online.setBrowser(session.getBrowser());
/*  55 */           online.setOs(session.getOs());
/*  56 */           online.setStatus(session.getStatus());
/*  57 */           ((ISysUserOnlineService)SpringUtils.getBean(ISysUserOnlineService.class)).saveOnline(online);
/*     */         }
/*     */       };
/*     */   }
/*     */   
/*     */   public static TimerTask recordOper(final SysOperLog operLog) {
/*  71 */     return new TimerTask() {
/*     */         public void run() {
/*  77 */           operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp()));
/*  78 */           ((ISysOperLogService)SpringUtils.getBean(ISysOperLogService.class)).insertOperlog(operLog);
/*     */         }
/*     */       };
/*     */   }
/*     */   
/*     */   public static TimerTask recordLogininfor(final String username, final String status, final String message, Object... args) {
/*  94 */     final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
/*  95 */     final String ip = ShiroUtils.getIp();
/*  96 */     return new TimerTask() {
/*     */         public void run() {
/* 101 */           String address = AddressUtils.getRealAddressByIP(ip);
/* 102 */           StringBuilder s = new StringBuilder();
/* 103 */           s.append(LogUtils.getBlock(ip));
/* 104 */           s.append(address);
/* 105 */           s.append(LogUtils.getBlock(username));
/* 106 */           s.append(LogUtils.getBlock(status));
/* 107 */           s.append(LogUtils.getBlock(message));
/* 109 */           AsyncFactory.sys_user_logger.info(s.toString(), args);
/* 111 */           String os = userAgent.getOperatingSystem().getName();
/* 113 */           String browser = userAgent.getBrowser().getName();
/* 115 */           SysLogininfor logininfor = new SysLogininfor();
/* 116 */           logininfor.setLoginName(username);
/* 117 */           logininfor.setIpaddr(ip);
/* 118 */           logininfor.setLoginLocation(address);
/* 119 */           logininfor.setBrowser(browser);
/* 120 */           logininfor.setOs(os);
/* 121 */           logininfor.setMsg(message);
/* 123 */           if (MyStringUtils.equalsAny(status, new CharSequence[] { "Success", "Logout", "Register" })) {
/* 125 */             logininfor.setStatus("0");
/* 127 */           } else if ("Error".equals(status)) {
/* 129 */             logininfor.setStatus("1");
/*     */           } 
/* 132 */           ((SysLogininforServiceImpl)SpringUtils.getBean(SysLogininforServiceImpl.class)).insertLogininfor(logininfor);
/*     */         }
/*     */       };
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-framework-4.7.0.jar!\com\cr\framework\manager\factory\AsyncFactory.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */